package com.meatball.core.config

import com.fasterxml.jackson.annotation.JsonInclude
import io.swagger.v3.oas.annotations.media.Schema

/**
 * 统一数据返回包装类
 * @author 张翔宇
 * @since 2023年10月9日
 * @version 1.0
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "统一数据返回包装类")
data class BaseResponse(
    /**
     * 业务数据
     */
    @Schema(title = "业务数据")
    val data: Any? = null,

    /**
     * 状态
     * @mock 200
     */
    @Schema(title = "状态", example = "200")
    val status: Int = 200,

    /**
     * 消息
     * @mock 操作成功
     */
    @Schema(title = "消息", example = "操作成功")
    val message: String = "操作成功",

    /**
     * 当前时间戳
     */
    @Schema(title = "当前时间戳")
    val serviceTime: Long = System.currentTimeMillis()
) {
    companion object {
        fun ok(): BaseResponse {
            return BaseResponse()
        }

        fun ok(data: Any): BaseResponse {
            return BaseResponse(data = data)
        }

        fun error(status: Int, message: String): BaseResponse {
            return BaseResponse(status = status, message = message)
        }
    }
}
